<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="__MOBILE__/sport/css/vendor.css" rel="stylesheet">
<link href="__MOBILE__/sport/css/app.css" rel="stylesheet">
<script type="text/javascript" src="__MOBILE__/sport/js/vendor.js"></script>
<script type="text/javascript" src="__MOBILE__/sport/js/jquery.js"></script>

</head>
<body>

<div class="bet-info"><div class="do-bet-info" style="padding:0;"><div>{$order.home_team} vs {$order.away_team}</div><div>{$order.wanfa} {$order.odds_name}&nbsp; &nbsp; <span class="rate-info">{$order.odds}</span></div><div class="suggest"><span class="btn btn-warning" data-money="100">100</span><span class="btn btn-warning" data-money="500">500</span><span class="btn btn-warning" data-money="1000">1,000</span><span class="btn btn-warning" data-money="5000">5,000</span><span class="btn btn-warning" data-money="10000">10,000</span><span class="btn btn-warning" data-money="20000">20,000</span></div><div>下注金额：<input type="number" placeholder="填写下注金额" class="bet_money auto-scroll-to" ></div><div>可赢金额：<span class="calc-win">0.00</span></div><div class="btn-area"><button class="btn btn-primary do-bet-btn" type="button">下注</button></div></div></div>
   <input type="hidden" name="match_id" value="<?php echo $order['match_id']?>">
    <input type="hidden" name="stype" value="<?php echo $order['stype']?>">
    <input type="hidden" name="type" value="<?php echo $order['type']?>">
    <input type="hidden" name="btype" value="<?php echo $order['btype']?>">  
    <input type="hidden" name="wanfa" value="<?php echo $order['wanfa']?>">  
    <input type="hidden" name="odds_name" value="<?php echo $order['odds_name']?>">  
<input type="hidden" id="odds_type" value="{$odds_type}">

</body>

<script>
$(function(){
  parent.frameHeight("orderFrame",$(".bet-info").height());
  $("body").on("click",".suggest .btn",function() {
    var betMoneyInput = $(".bet_money");
        betMoneyInput.val($(this).data("money"));
        betMoneyInput.change();
  });
  $("body").bind("change input",".bet_money",function() {
    var rate = Number($(".rate-info").text());
    var money = Number($(".bet_money").val());
    var calcResult = 0;
	var odds_type=$("#odds_type").val();
	if(odds_type==1){
	calcResult = money * (rate-1);
	}else{
	calcResult = money * rate;
	}
    
    $(".calc-win").text(formatMoney(calcResult));    
  });
  $("body").on("click",".do-bet-btn",function(){
    var betMoneyInput = $(".bet_money");
    var _this = this;
    var betMoney = $.trim(betMoneyInput.val());
    if (!betMoney && !betMoneyInput[0].validationMessage) {
        alert("请填写下注金额");
        betMoneyInput.focus();
        return;
    }
    if (/\./.test(betMoney)) {
        alert("请填写整数金额");
        betMoneyInput.focus();
        return;
    }
    if (!/^\d+$/.test(betMoney)) {
        alert("请填写正确的金额");
        betMoneyInput.focus();
        return;
    }
	
	var match_id=$("input[name='match_id']").val();
	var stype=$("input[name='stype']").val();
	var type=$("input[name='type']").val();
	var btype=$("input[name='btype']").val();
	var odds_name=$("input[name='odds_name']").val();
	var wanfa=$("input[name='wanfa']").val();
	
	$.post('/index.php/sport/doorder',{gold:betMoney,stype:stype,type:type,btype:btype,match_id:match_id},function(matchData){
	if(matchData.result==1){
	if(confirm(matchData.msg)){
	$.post('/index.php/sport/doorder',{odds_name:odds_name,wanfa:wanfa,gold:betMoney,stype:stype,type:type,btype:btype,match_id:match_id,queren:1},function(matchData){
	if(matchData.status==1){
	window.location.href='/index.php/sport/order_list';
	}else{
	alert(matchData.msg);
	}
	    },'json')
	
	}
	}else{
	alert(matchData.msg)
	}
	
	},'json')
	
  });
});
function formatMoney(number, places, symbol, thousand, decimal) {
    number = number || 0;
    places = !isNaN(places = Math.abs(places)) ? places : 2;
    symbol = symbol || "";
    thousand = thousand || "";
    decimal = decimal !== undefined ? decimal : ".";
    var negative = number < 0 ? "-" : ""
      , i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + ""
      , j = (j = i.length) > 3 ? j % 3 : 0;
    return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
}
</script>
</html>